<?php

namespace App\Service\User\v1_1_4;

use App\Constants\ErrorCode;
use App\Model\Act\ProfileRewardLog;
use App\Model\ProfileVerifyLog;
use App\Model\UserQa;
use App\Service\BaseService;

/**
 * 专访回答
 */
class QuestionAnswerService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $questionId = $this->request->input('question_id', 0);
        $answer = $this->request->input('answer', '');
        if (!$questionId) return $this->setError(ErrorCode::PARAMETER_ERROR, '参数有误！');
        $result = UserQa::addRecord($userId, $questionId, $answer);
        //审核记录
        ProfileVerifyLog::addRecord($userId, ProfileVerifyLog::TYPE_QA, ['question_id' => $questionId, 'answer' => $answer]);
        ProfileRewardLog::doReward($userId, 'question', 2);
        return ['result' => $result ? 1 : 0];
    }
}
